﻿<?php 

//Kiem tra tai khoan can bo giao
// Khoi tao bien session $_SESSION['arr_all_staff_user_pass'] de luu thong tin ca nhan cua tat ca staff
if(!isset($_SESSION['arr_all_staff_user_pass']) or (isset($_SESSION['arr_all_staff_user_pass']) and sizeof($_SESSION['arr_all_staff_user_pass'])==0)){
	$p_arr_items = array();
	$p_level1_tag_name = "staff";
	$p_level2_tag_name_list= "id,name,username,pass";
	$p_delimitor = ",";
	_get_personal_info_of_all_staff();
	$_SESSION['arr_all_staff_user_pass'] = $p_arr_items;
	//var_dump($p_arr_items); exit;
	//echo '---+';
	unset($p_arr_items);
}
$array_check = $_SESSION['arr_all_staff_user_pass'];
//var_dump($array_check[0]['name']); exit;

$v_staff_name_giver = '';
$v_staff_name_giver_user = $_REQUEST['txt_staff_name_giver_user'];
$v_staff_name_giver_pass = $_REQUEST['txt_staff_name_giver_pass'];
	//echo 'username:'.$v_staff_name_giver_user.' pass:'.$v_staff_name_giver_pass;
if($v_staff_name_giver_user!= '' || $v_staff_name_giver_pass!= ''){
	for($i = 1; $i<sizeof($array_check); $i++){
	//echo 'user-pass:'.$array_check[$i]['username'].'/'.$array_check[$i]['pass'].'<br/>';
		if($array_check[$i]['username']==$v_staff_name_giver_user && $array_check[$i]['pass']==$v_staff_name_giver_pass){
			$v_staff_name_giver = ' (C&aacute;n b&#7897; giao: '.$array_check[$i]['name'].')';
		}
	}
	unset($_SESSION['arr_all_staff_user_pass']);
	unset($array_check);
	//exit;
	if($v_staff_name_giver == ''){
		?><script>
			alert("Tài khoản hay Mật khẩu của Cán bộ giao không đúng! Yêu cầu thực hiện lại!. "); 
			window.history.back();
		</script><?php
	}
}
else{
	$v_staff_name_giver = ' (Kh&ocirc;ng c&oacute; c&aacute;n b&#7897; x&aacute;c nh&#7853;n giao.)';	
}

//	echo $v_staff_name_giver;
//	exit;
//========================================================================
$v_record_id = 0;

if(isset($_REQUEST['hdn_record_id_list'])){
	$v_record_id_list = $_REQUEST['hdn_record_id_list']; //Ma ho so
	$v_array_id = explode("," , $v_record_id_list);
	$v_count = sizeof($v_array_id);
}

if(isset($_REQUEST['hdn_record_id'])){
	$v_record_id = intval($_REQUEST['hdn_record_id']); //Ma ho so
}

$v_worker_id = intval($_REQUEST['hdn_staff_id']); //Ma nguoi thuc hien cong viec

$v_worktype = $_REQUEST['hdn_worktype']; //Loai cong viec thuc hien

$v_date= _ddmmyyyy_to_yyyymmdd($_REQUEST['txt_receive_date']); //Ngay thuc hien

$v_result = _replace_bad_char($_REQUEST['txt_result']).$v_staff_name_giver ; //Ket qua thuc hien

$v_record_work_id = 0;
$v_file_id = 0;	
//echo $v_record_id.'/'.$v_staff_id.'/'.$v_worktype.'/'.$v_date.'/'.$v_result; exit;
//$v_url = "/record/handle/index.php?modal_dialog_mode=1"."&hdn_record_work_id=".$v_record_work_id."&fuseaction=DISPLAY_NOTIFY" ;

//CSDL SQL
if(_is_sqlserver()){
	if($v_count<=1){
	$v_result_id = _save_text_to_database('T_TEMP_FILE', 'C_TEXT', $v_result);
		$sql = "Exec Onegate_RecordWorkUpdate ";
		$sql = $sql . $v_record_work_id;
		$sql = $sql . "," . $v_record_id;
		$sql = $sql . "," . $v_worker_id;//ID nguoi thuc hien cong viec
		$sql = $sql . ",'" . $v_worktype . "'";
		$sql = $sql . ",'" . $v_date."'";
		$sql = $sql . "," . $v_result_id ;
		$sql = $sql . "," . $v_file_id;
		$sql = $sql . ",'" ."Ox"."'";
		$sql = $sql . "," . _CONST_STATUS_UPDATE_DATE ;
		$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
		$rs = $ado_conn->GetRow($sql); 
		$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
	}
	else{
		for($i=0;$i<$v_count;$i++){
		$v_result_id = _save_text_to_database('T_TEMP_FILE', 'C_TEXT', $v_result);
			$sql = "Exec Onegate_RecordWorkUpdate ";
			$sql = $sql . $v_record_work_id;
			$sql = $sql . "," . $v_array_id[$i];
			$sql = $sql . "," . $v_worker_id;	//ID nguoi thuc hien cong viec
			$sql = $sql . ",'" . $v_worktype . "'";
			$sql = $sql . ",'" . $v_date."'";
			$sql = $sql . "," . $v_result_id ;
			$sql = $sql . "," . $v_file_id;
			$sql = $sql . ",'" ."Ox"."'";
			$sql = $sql . "," . _CONST_STATUS_UPDATE_DATE ;
			$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
//			echo $sql.'<br/>'; 
			$rs = $ado_conn->GetRow($sql); 
			$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
		}
//		exit;
	}
}

if (!is_null($v_error) and $v_error<>""){?>
	<script>
		alert("<?php echo $v_error; ?>");
		if (_MODAL_DIALOG_MODE==1){
		//alert("vo day.....1");
			window.location = "<?php echo $v_url; ?>";
		}else{
			//alert("vo day.....2");
			window.history.back();
		}	
	</script><?php
	exit;
}
sleep(0);
?>
<form action="index.php" method="post" name="f_back">
	<input type="hidden" name="fuseaction" value="">
	<input type="hidden" name="hdn_record_id"  value="<?php echo $v_record_id; ?>">
	<input type="hidden" name="hdn_recordtype_filter" value="<?php echo $hdn_recordtype_filter;?>">
	<input type="hidden" name="hdn_item_id" value="<?php echo $v_record_work_id;?>">
</form>
<Script language="javascript">
	<!--DatCQ 12/08/2008 lay fuseaction quay lai trang-->
	document.forms(0).fuseaction.value = "<?php echo $_REQUEST['back_fuseaction'];?>" ;
	document.forms(0).submit();
</Script>
